<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Quick Start</title>
  <script src="/js/spritejs.js"></script>
  <script src="//lib.baomitu.com/d3/4.10.2/d3.js"></script>
  <style>
    html,body {
      margin: 0;
      padding: 0;
      height: 100%;
      width: 100%;
      max-width: 800px;
    }

    #stage {
      display: inline-block;
      width: 100%;
      height: 0;
      padding-bottom: 100%;
    }  
  </style>
</head>
<body>
  <div id="stage"></div>
  <script>
    /* globals d3 */
    const {Scene, Sprite} = spritejs;
    const container = document.getElementById('stage');
    const scene = new Scene({
      container,
      width: 1200,
      height: 1200,
    });

    const layer = scene.layer('fglayer');

    for(let i = 0; i < 6; i++) {
      const s = new Sprite({
        size: [50, 50],
        bgcolor: 'green',
        pos: [100 * i, 200],
      });
      layer.append(s);
    }

    const selection = d3.select(layer)
      .selectAll('sprite')
      .data([100, 200, 300, 400]);

    selection
      // .enter()
      // .append('sprite')
      .attr('pos', d => [d, 100])
      .attr('size', [50, 50])
      .attr('bgcolor', 'red');

    const exit = selection.exit();
    // debugger;
    exit.remove();
  </script>
</body>
</html>